package com.sgb.goods.view.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import androidx.core.content.res.ResourcesCompat;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.entity.ContractInfoEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;

/**
 * 合同列表adapter
 * @author cyj
 */
public class ContractInfoListAdapter extends BaseCommonAdapter<ContractInfoEntity.Records> {

    public ContractInfoListAdapter() {
        super(R.layout.goods_item_contract_info);
    }

    @Override
    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, ContractInfoEntity.Records entity) {
        dataBinding.setVariable(BR.data, entity);
        dataBinding.setVariable(BR.adapter, this);

        // 为什么这里这么长的判断？？？后面有时间在优化
        baseHolder.getView(R.id.ll_see_contract).setVisibility("1".equals(entity.isTaker)||"3".equals(entity.status) || "4".equals(entity.status) || ("5".equals(entity.status) && 1 == entity.signStatus) || "6".equals(entity.status) || "7".equals(entity.status) ? View.VISIBLE : View.GONE);

        baseHolder.setImageDrawable(R.id.status_img, setContractStateImg(entity));


        baseHolder.addOnClickListener(R.id.see_contract);
    }

    /**
     * status 合同状态 1:拟定中，，3：已完成，4：已过期，5，已作废 7 待我方签署，6 待对方签署	string
     *
     * @param bean ContractListSearchBean.ContractListInfo
     * @return Drawable
     */
    private Drawable setContractStateImg(ContractInfoEntity.Records bean) {
        if ("1".equals(bean.status)) {
            return ResourcesCompat.getDrawable(mContext.getResources(), R.mipmap.goods_ic_contract_state1, null);
        } else if ("6".equals(bean.status)) {
            return ResourcesCompat.getDrawable(mContext.getResources(), R.mipmap.goods_ic_contract_state2, null);
        } else if ("7".equals(bean.status)) {
            return ResourcesCompat.getDrawable(mContext.getResources(), R.mipmap.goods_ic_contract_state3, null);
        } else if ("3".equals(bean.status)) {
            return ResourcesCompat.getDrawable(mContext.getResources(), R.mipmap.goods_ic_contract_state4, null);
        } else if ("4".equals(bean.status)) {
            return ResourcesCompat.getDrawable(mContext.getResources(), R.mipmap.goods_ic_contract_state5, null);
        } else if ("5".equals(bean.status)) {
            return ResourcesCompat.getDrawable(mContext.getResources(), R.mipmap.goods_ic_contract_state6, null);
        } else if ("8".equals(bean.status)){
            return ResourcesCompat.getDrawable(mContext.getResources(), R.mipmap.goods_ic_contract_state7, null);
        }
        return null;
    }
}
